//
//  BJOpenURlManager.m
//  小码哥彩票
//
//  Created by Rip on 17/4/25.
//  Copyright © 2017年 simplyou. All rights reserved.
//

#import "BJOpenURlManager.h"
BJOpenURlManager* manager;
@implementation BJOpenURlManager

+(BJOpenURlManager *)defulatManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc]init];
        
    });
    return manager;
}
-(void)isOpenUrlCompelete:(getOpenUrl)compelete
{
    NSURLSession* urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    NSString* urlStr = [NSString stringWithFormat:@"%@?appid=%@",APPURL,APPOPENID];
    NSURL* url = [NSURL URLWithString:urlStr];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
   NSURLSessionTask* task = [urlSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
       
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (data==nil) {
                compelete(NO,nil);
                return ;
            }
            id jsonDic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
            if (![jsonDic isKindOfClass:[NSDictionary class]]) {
                compelete(NO,nil);
                return ;
            }
            
            if ([jsonDic isKindOfClass:[NSDictionary class]]) {
                NSString* isShow = nil;
                NSString* wapUrl = nil;
                NSString* status = nil;
                isShow = [jsonDic objectForKey:@"isshowwap"];
                wapUrl = [jsonDic objectForKey:@"wapurl"];
                status = [jsonDic objectForKey:@"status"];
                
                if ([status integerValue]==1) {
                    
                    if ([isShow integerValue]==1) {
                        if (wapUrl!=nil&&wapUrl.length>1) {
                            
                            compelete(YES,jsonDic);
                        }else{
                            compelete(NO,nil);
                        }
                        
                        
                    }else{
                        compelete(NO,nil);
                    }
                    
                }else{
                    
                    compelete(NO,nil);
                }
            }
            

            
        });
        
        
        
    }];
    [task resume];
}

@end
